/*
 * CandleStickRangeCalculator.java
 * Android-Charts
 *
 * Created by limc on 2011/05/29.
 *
 * Copyright 2011 limc.cn All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.limc.androidcharts.model;

import cn.limc.androidcharts.series.IMeasurable;
import cn.limc.androidcharts.series.OHLCEntity;

/**
 * CandleStickRangeCalculator
 * Description: <br>
 *   <p>add description here </p>
 * Tags: <br>
 *   <p> </p>
 *
 * @author limc
 * @version v1.0 
 * 
 * History: <br>
 * 2015-7-22 limc create v1.0 <br>
 *
 */
public abstract class CandleStickRangeCalculator extends MeasuableRangeCalculator {
 

    public void compareValue(DataRange dataRange,IMeasurable ohlc) {

        double maxValue = dataRange.getMaxValue();
        double minValue = dataRange.getMinValue();

        
        OHLCEntity stick = (OHLCEntity) ohlc;
        
        if (stick.getOpen() == 0 && stick.getHigh() == 0
                && stick.getLow() == 0) {
            // 停盘期间计算收盘价
            if (stick.getClose() > 0) {
                if (stick.getClose() < minValue) {
                    dataRange.setMinValue(stick.getLow());
                }

                if (stick.getClose() > maxValue) {
                    dataRange.setMaxValue(stick.getHigh());
                }
            }
        } else {
            if (stick.getLow() < minValue) {
                dataRange.setMinValue(stick.getLow());
            }

            if (stick.getHigh() > maxValue) {
                dataRange.setMaxValue(stick.getHigh());
            }
        }
    }
}
